<template>
  <view class="container">
    <button @tap="scanCode">扫码</button>
  </view>
</template>

<script>
export default {
  methods: {
    scanCode() {
      uni.scanCode({
        success: (res) => {
          console.log('扫码结果：', res.result)
          uni.showToast({
            title: '扫码成功：' + res.result,
            icon: 'success',
            duration: 2000
          })
        },
        fail: (res) => {
          console.log('扫码失败：', res.errMsg)
          uni.showToast({
            title: '扫码失败',
            icon: 'none',
            duration: 2000
          })
        }
      })
    }
  }
}
</script>
